//
//  CrazyChatCustomListCell.m
//  webSocket
//
//  Created by 马军凯 on 2019/2/12.
//  Copyright © 2019年 ZH. All rights reserved.
//

#import "CrazyChatCustomListCell.h"
#import "Crazy_TimeChange.h"

@implementation CrazyChatCustomListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self setLayoutSubView];
    }
    return self;
}

//加载视图
- (void)setLayoutSubView {
    //logo
    self.logoImageView = [[UIImageView alloc] init];
    self.logoImageView.frame = CGRectMake(15, 10, 60, 60);
    [self.contentView addSubview:self.logoImageView];
    //时间
    self.timeLabel = [[UILabel alloc] init];
    self.timeLabel.textColor = CRAZY_RGBR(99);
    self.timeLabel.font = [UIFont systemFontOfSize:11];
    [self.contentView addSubview:self.timeLabel];
    //名称
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.textColor = CRAZY_RGBR(33);
    self.nameLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.nameLabel];
    //内容
    self.contentLabel = [[UILabel alloc] init];
    self.contentLabel.frame = CGRectMake(85, 50, CRAZY_SCREEN_WIDTH - 100, 20);
    self.contentLabel.textColor = CRAZY_RGBR(66);
    self.contentLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.contentLabel];
    //未读数量
    self.noReadLabel = [[UILabel alloc] init];
    self.noReadLabel.frame = CGRectMake(CRAZY_SCREEN_WIDTH - 30, 30, 15, 15);
    self.noReadLabel.backgroundColor = [UIColor redColor];
    self.noReadLabel.textColor = [UIColor whiteColor];
    [self.noReadLabel corner_radius:self.noReadLabel.height / 2];
    self.noReadLabel.textAlignment = NSTextAlignmentCenter;
    self.noReadLabel.font = [UIFont systemFontOfSize:10];
    [self.contentView addSubview:self.noReadLabel];
}


//赋值
- (void)setModel:(CrazyChatCustomListModel *)model {
    _model = model;
    //logo
    [self.logoImageView sd_setImageWithURL:[NSURL URLWithString:model.logo] placeholderImage:CRAZY_DEFAULT_LOADIMAGE];
    //时间
    self.timeLabel.text = [Crazy_TimeChange timeStringChangeTime:model.after_chat_time];
    [self.timeLabel sizeToFit];
    self.timeLabel.x = CRAZY_SCREEN_WIDTH - 15 - self.timeLabel.width;
    self.timeLabel.height = 20;
    self.timeLabel.y = 10;
    //标题
    self.nameLabel.text = model.store_name;
    self.nameLabel.frame = CGRectMake(85, 10, self.timeLabel.x - 8 - 85 - 10, 30);
    //内容
    if ([model.MESSAGE_TYPE isEqualToString:@"VOICE"]) {
        self.contentLabel.text = @"[语音]";
    } else if ([model.MESSAGE_TYPE isEqualToString:@"IMAGE"]) {
        self.contentLabel.text = @"[图片]";
    } else if ([model.MESSAGE_TYPE isEqualToString:@"GOODS"]) {
        self.contentLabel.text = @"[商品]";
    } else if ([model.MESSAGE_TYPE isEqualToString:@"ORDER"]) {
        self.contentLabel.text = @"[订单]";
    } else if ([model.MESSAGE_TYPE isEqualToString:@"TEXT"]) {
        self.contentLabel.text = model.MESSAGE_DATA;
    } else {
        self.contentLabel.text = @"";
    }
    //未读消息
    if (model.messageNoReadCount > 99) {
        self.noReadLabel.text = @"99+";
        self.noReadLabel.font = [UIFont systemFontOfSize:7];
    } else {
        self.noReadLabel.font = [UIFont systemFontOfSize:10];
        self.noReadLabel.text = [NSString stringWithFormat:@"%ld", model.messageNoReadCount];
    }
    if (model.messageNoReadCount > 0) {
        self.noReadLabel.hidden = NO;
    } else {
        self.noReadLabel.hidden = YES;
    }
}




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
